package club.xyes.zkh.ecommerce.service.util;

import club.xyes.zkh.ecommerce.commons.dto.ConsumptionOverview;
import club.xyes.zkh.ecommerce.commons.entity.Shop;
import club.xyes.zkh.ecommerce.commons.entity.ShopMembershipLevel;
import club.xyes.zkh.ecommerce.commons.entity.User;
import club.xyes.zkh.ecommerce.service.ShopMembershipLevelService;
import club.xyes.zkh.ecommerce.service.TransactionLogService;

/**
 * Create by 郭文梁 2019/4/22 0022 10:36
 * UserMembershipFunctions
 * 用户会员相关函数
 *
 * @author 郭文梁
 * @data 2019/4/22 0022
 */
public class UserMembershipFunctions {
    /**
     * 获取符合用户条件的会员等级
     *
     * @param transactionLogService      交易记录业务组件
     * @param shopMembershipLevelService 商家会员等级业务组件
     * @return 会员等级定义
     */
    public static ShopMembershipLevel getLevel(User user,
                                               Shop shop,
                                               TransactionLogService transactionLogService,
                                               ShopMembershipLevelService shopMembershipLevelService) {
        ConsumptionOverview consumptionOverview = transactionLogService.getConsumptionOverview(shop, user);
        return shopMembershipLevelService.highestLevelOfMatching(shop, consumptionOverview.getTotalFee(), consumptionOverview.getTimes());
    }
}
